'''
Created on 2024年7月24日

@author: Administrator
'''
import pygame
from pygame.sprite import Sprite



class Ship(Sprite):
    def __init__(self,ai_game):
        super().__init__()
        self.screen = ai_game.screen
        self.settings = ai_game.settings
        
        self.screen_rect = ai_game.screen.get_rect()
        
        
        self.image = pygame.image.load('images/ship.jpeg')
        self.image = pygame.transform.scale(self.image, (50, 50))
        self.rect = self.image.get_rect()
#         print(dir(self.rect))
#         self.rect.width /=50
#         self.rect.height /=50
        
        self.rect.midbottom = self.screen_rect.midbottom
        
        self.x = float(self.rect.x)
        
        self.moving_right = False
        self.moving_left = False
        
        
    
    def update(self):
        if self.moving_right and self.rect.right < self.screen_rect.right :
#             self.rect.x += 1
            self.x += self.settings.ship_speed
        if self.moving_left and self.rect.left > 0:
#             self.rect.x -= 1
            self.x -= self.settings.ship_speed
        self.rect.x = self.x
        
    def blitme(self):
        self.screen.blit(self.image,self.rect)
        
        
    def center_ship(self):    
        self.rect.midbottom = self.screen_rect.midbottom
        self.x = float(self.rect.x)
        
        
        